/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef C_PARSER_H
#define C_PARSER_H

/**
 * This simple parser is the replacement for the xml-parser.
 * Format:
 * name [attrib value] [...]
 */

#include <stdlib.h>
#include <string.h>

typedef void (*on_begin)(void*, char *, char **);

/** 
 * \brief This struct is a internal structure and holds the data which should be
 * parsed. 
 */
typedef struct parseable_t {
	char *to_parse;
	int size;
} parseable;

/** 
 * \brief This struct represents a parser.
 */
typedef struct parser_t {
	void *userdata;
	on_begin callback;
	parseable *p;
} parser;

/** 
 * \brief parse parses with the corresponding parse-object.
 * 
 * \param pars is the parse-object which should be parsed
 * 
 * \return true (1) if successful
 */
int parse(parser *pars);
/** 
 * \brief parser_create creates a new parser-object
 * 
 * \return a pointer to a new parser-object is returned
 */
parser* parser_create();
/** 
 * \brief parser_delete deletes a parser-object
 * 
 * \param p is the object which should be deleted
 */
void parser_delete(parser *p);

/** 
 * \brief parse_add adds a character which should be parsed to the parse-struct.
 * 
 * \param p is the parser-object
 * \param c is the character, which should be parsed.
 */
void parse_add(parser *p, char c);

#endif
